package com.hxit.huaxiamelongarden.service.impl;

import com.hxit.huaxiamelongarden.domin.dto.FavoritesDto;
import com.hxit.huaxiamelongarden.domin.po.Content;
import com.hxit.huaxiamelongarden.domin.po.Favorites;
import com.hxit.huaxiamelongarden.mapper.ContentMapper;
import com.hxit.huaxiamelongarden.mapper.FavoritesMapper;
import com.hxit.huaxiamelongarden.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @ClassName FavoritesServiceImpl
 * @description FavoritesServiceImpl
 * @Author 12694
 * @Date 2025/1/28 14:08
 * @Version 1.0
 **/
@Service
public class FavoritesServiceImpl implements FavoritesService {
    @Autowired
    private FavoritesMapper favoritesMapper;
    @Autowired
    private ContentMapper contentMapper;
    //查询收藏列表
    @Override
    public FavoritesDto selectFavoritesByUserId(Integer userId) {
        List<Favorites> favorites = favoritesMapper.selectFavoritesByUserId(userId);
        List<Content> contents = favorites.stream().map(favorites1 -> {
            Content contentPo = contentMapper.getCommentsByContentId(favorites1.getContentId());
            return contentPo;
        }).collect(toList());
        FavoritesDto favoritesDto = new FavoritesDto();
        favoritesDto.setContentList(contents);
        return favoritesDto;
    }
}
